# -*- coding: utf-8 -*-
import scrapy


class MtimeSpider(scrapy.Spider):
    name = 'mtime'
    allowed_domains = ['mtime.com']
    start_urls = ['http://movie.mtime.com/253688/reviews/short/new.html']

    def parse(self, response):
        item = {}
        comment = []
        for dd in response.xpath('//dl[@id="tweetRegion"]/dd'):
            content = dd.xpath('./div/h3/text()').extract_first()
            comment.append(content)
        item['comment'] = comment
        #检测下一页
        next_url= response.xpath('//a[@id="key_nextpage"]/@href').extract_first()
        if next_url is not None:
            yield scrapy.Request(
                next_url,
                callback=self.parse
            )
        yield item
